from flask import jsonify, render_template, redirect, request, url_for, flash, send_file
from flask_login import login_user, logout_user, login_required
from .. import utils
from ..models import User
from ..auth.forms import LoginForm
from . import main


@main.route('/')
def index():
    return render_template('index.html')

@main.route('/analysis_ifoton')
def analysis_ifoton():
    return send_file('templates/analysis_ifoton.html')

@main.route('/analysis_JT808')
def analysis_JT808():
    return send_file('templates/analysis_JT808.html')

@main.route('/analysis_JT1078')
def analysis_JT1078():
    return send_file('templates/analysis_JT1078.html')

@main.route('/bd_platform')
def bd_platform():
    return send_file('templates/bd_platform.html')

@main.route('/bubiaoji')
def bubiaoji():
    return send_file('templates/bubiaoji.html')

@main.route('/op_platform')
def op_platform():
    return send_file('templates/op_platform.html')

@main.route('/tbox1')
def tbox1():
    return send_file('templates/tbox1.html')

@main.route('/tbox2')
def tbox2():
    return send_file('templates/tbox2.html')

@main.route('/os40')
def os40():
    return send_file("templates/os40.html")

@main.route('/os50')
def os50():
    return send_file("templates/os50.html")

@main.route('/exe_cmd')
@login_required
def exe_cmd():
    return send_file("templates/cmd.html")

#HEX To GB2312
@main.route('/hex2gb2312/<hex_input>')
def hex2gb2312(hex_input):
    if hex_input == 'Unknown' or hex_input == '':
        return 'Unknown'
    hex_input=hex_input
    utf8_output = hex_input.decode('hex')
    gb2312_output = utf8_output.decode('gb2312')
    return gb2312_output
